nums = [1, 3, -1, -3, 5, 3, 6, 7], k = 3

var maxSlidingWindow = function (nums, k) {

    const len = nums.length
    const res = []
    let i = 0, j = k - 1;
    //实现一段代码使指针移动
    while (j < len) {
        const max = calMax(nums, i, j)
        res.push(max)

        i++
        j++
    }
    return res
}

function calMax(arr, i, j) {

    let max = -Infinity
    for (let m = i; m <= j; m++) {
        if (arr[m] > max) {
            max = arr[m]
        }
    }
    return max
}

console.log(maxSlidingWindow(nums, k));
